home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11646 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: jaring.my!n16872!ckyin
  2. From: ckyin@n16872.pc.jaring.my (Yin Chee Kin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginer C please help me
  5. Message-ID: <827821769.0snx@n16872.pc.jaring.my>
  6. References: <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de>
  7. Date: Tue, 26 Mar 96 06:29:29 GMT
  8. Organization: Pantai Dalam
  9.  
  10. In article <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de> schoof@informatik.uni-wuerzburg.de writes:
  11. >
  12. >Scott Shrader (shrader@scsn.net) wrote:
  13. >: In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net says...
  14. >: >
  15. >: >This may be a stupid mistake but "please help" me.
  16. >: >Thank you very much.
  17. >: >
  18. >: >#include <stdio.h>
  19. >: >#include <math.h>
  20. >: >main ()
  21. >: >{
  22. >: >float n;
  23. >: >n=(9/5);
  24. >: >printf ("n=   %1.3f\n", n);
  25. >: >}
  26. >: >I have complied and run the programme & I got the answer n=1.000
  27. >: >but Iam supposed to get answer 1.8.
  28. >: >Why I got this answer?
  29. >: >-- 
  30. >: you can write this by skipping  printf("n=   %1.3f\n", n); and put in 
  31. >: printf("%f",n);
  32. >:
  33. >: Try this to see how this works. 
  34. >
  35. >What you wrote is complete nonsense. How about testing the programs
  36. >before posting them..? Even learning C might be of help.
  37. >
  38. >: I'm a bit new at this too, but I think this will work.
  39. >
  40. >If you have to use phrases like "I think it will work" or "I'm not sure"
  41. >in your posting, please don't post it. There are enough folks around 
  42. >here who know for sure - especially in elementary cases like this one.
  43. >
  44. >- Jochen
  45. >
  46. >--
  47. >--------------------------------------------------------------------------
  48. > Jochen Schoof                  mailto:schoof@informatik.uni-wuerzburg.de
  49. > Lehrstuhl fuer Informatik II +-------------------------------------------
  50. > Universitaet Wuerzburg       | You are just reading a .sig-light:
  51. > D-97074 Wuerzburg (Germany)  | It is free of fat, sugar and cholesterol!
  52. >------------------------------+-------------------------------------------
  53. > WWW-Homepage:        http://www.informatik.uni-wuerzburg.de/staff/joscho
  54. >--------------------------------------------------------------------------
  55. >
  56.  
  57. Jochen,
  58.  
  59.   I agree with you completely. What a complete nonsense!  
  60.   
  61.   In order a get correct answer, should try this:
  62.  
  63.      n = 9.0/5  or n = 9/5.0 or  n = 9/5*1.0 
  64.  
  65.   Remember, in C you may not get a floating point answer by division
  66.   using integer only!
  67.  
  68.   I hope this will help!
  69.  
  70.  
  71.  
  72.  
  73.